package everyday;

import org.junit.jupiter.api.Test;

public class T2383 {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int num1=0,num2=0;
        int energySum=0;
        for (int i = 0; i <experience.length ; i++) {
            energySum+=energy[i];
            if (initialExperience<=experience[i]){
                int tmp=experience[i]-initialExperience+1;
                initialExperience+=tmp;
                num2+=tmp;
            }
            initialExperience+=experience[i];
        }
        if (initialEnergy<=energySum){
            num1=energySum-initialEnergy+1;
        }
        return num1+num2;
    }

    @Test
    public void test() {
        int []energy={1,4,3,2};
        int [] experience={2,6,3,1};
        System.out.println(minNumberOfHours(5,3,energy,experience));

    }
}
